package com.bestow.basic.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.bestow.common.annotation.Log;
import com.bestow.common.core.controller.BaseController;
import com.bestow.common.core.domain.AjaxResult;
import com.bestow.common.enums.BusinessType;
import com.bestow.basic.domain.FndUomType;
import com.bestow.basic.service.IFndUomTypeService;
import com.bestow.common.utils.poi.ExcelUtil;
import com.bestow.common.core.page.TableDataInfo;

/**
 * 计量单位定义Controller
 * 
 * @author liliu
 * @date 2022-09-07
 */
@RestController
@RequestMapping("/basic/fndUomType")
public class FndUomTypeController extends BaseController
{
    @Autowired
    private IFndUomTypeService fndUomTypeService;

    /**
     * 查询计量单位定义列表
     */
    @PreAuthorize("@ss.hasPermi('basic:fndUomType:list')")
    @GetMapping("/list")
    public TableDataInfo list(FndUomType fndUomType)
    {
        startPage();
        List<FndUomType> list = fndUomTypeService.selectFndUomTypeList(fndUomType);
        return getDataTable(list);
    }

    /**
     * 导出计量单位定义列表
     */
    @PreAuthorize("@ss.hasPermi('basic:fndUomType:export')")
    @Log(title = "计量单位定义", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, FndUomType fndUomType)
    {
        List<FndUomType> list = fndUomTypeService.selectFndUomTypeList(fndUomType);
        ExcelUtil<FndUomType> util = new ExcelUtil<FndUomType>(FndUomType.class);
        util.exportExcel(response, list, "计量单位定义数据");
    }

    /**
     * 获取计量单位定义详细信息
     */
    @PreAuthorize("@ss.hasPermi('basic:fndUomType:query')")
    @GetMapping(value = "/{uomType}")
    public AjaxResult getInfo(@PathVariable("uomType") String uomType)
    {
        return AjaxResult.success(fndUomTypeService.selectFndUomTypeByUomType(uomType));
    }

    /**
     * 新增计量单位定义
     */
    @PreAuthorize("@ss.hasPermi('basic:fndUomType:add')")
    @Log(title = "计量单位定义", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody FndUomType fndUomType)
    {
        return toAjax(fndUomTypeService.insertFndUomType(fndUomType));
    }

    /**
     * 修改计量单位定义
     */
    @PreAuthorize("@ss.hasPermi('basic:fndUomType:edit')")
    @Log(title = "计量单位定义", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody FndUomType fndUomType)
    {
        return toAjax(fndUomTypeService.updateFndUomType(fndUomType));
    }

    /**
     * 删除计量单位定义
     */
    @PreAuthorize("@ss.hasPermi('basic:fndUomType:remove')")
    @Log(title = "计量单位定义", businessType = BusinessType.DELETE)
	@DeleteMapping("/{uomTypes}")
    public AjaxResult remove(@PathVariable String[] uomTypes)
    {
        return toAjax(fndUomTypeService.deleteFndUomTypeByUomTypes(uomTypes));
    }
}
